home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / OptionsGeneralPage.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  5KB  |  163 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // OptionsGeneralPage.cpp: Implementierungsdatei
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "filezilla server.h"
  24. #include "OptionsDlg.h"
  25. #include "OptionsPage.h"
  26. #include "OptionsGeneralPage.h"
  27. #include <set>
  28.  
  29. #if defined(_DEBUG) && !defined(MMGR)
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Dialogfeld COptionsGeneralPage 
  37.  
  38.  
  39. COptionsGeneralPage::COptionsGeneralPage(COptionsDlg *pOptionsDlg, CWnd* pParent /*=NULL*/)
  40.     : COptionsPage(pOptionsDlg, COptionsGeneralPage::IDD, pParent)
  41. {
  42.     //{{AFX_DATA_INIT(COptionsGeneralPage)
  43.     m_MaxUsers = _T("");
  44.     m_Port = _T("");
  45.     m_Threadnum = _T("");
  46.     m_Timeout = _T("");
  47.     m_NoTransferTimeout = _T("");
  48.     m_LoginTimeout = _T("");
  49.     //}}AFX_DATA_INIT
  50. }
  51.  
  52.  
  53. void COptionsGeneralPage::DoDataExchange(CDataExchange* pDX)
  54. {
  55.     COptionsPage::DoDataExchange(pDX);
  56.     //{{AFX_DATA_MAP(COptionsGeneralPage)
  57.     DDX_Text(pDX, IDC_MAXUSERS, m_MaxUsers);
  58.     DDV_MaxChars(pDX, m_MaxUsers, 9);
  59.     DDX_Text(pDX, IDC_PORT, m_Port);
  60.     DDX_Text(pDX, IDC_THREADNUM, m_Threadnum);
  61.     DDV_MaxChars(pDX, m_Threadnum, 2);
  62.     DDX_Text(pDX, IDC_TIMEOUT, m_Timeout);
  63.     DDV_MaxChars(pDX, m_Timeout, 4);
  64.     DDX_Text(pDX, IDC_TRANSFERTIMEOUT, m_NoTransferTimeout);
  65.     DDV_MaxChars(pDX, m_NoTransferTimeout, 4);
  66.     DDX_Text(pDX, IDC_LOGINTIMEOUT, m_LoginTimeout);
  67.     DDV_MaxChars(pDX, m_LoginTimeout, 4);
  68.     //}}AFX_DATA_MAP
  69. }
  70.  
  71.  
  72. BEGIN_MESSAGE_MAP(COptionsGeneralPage, COptionsPage)
  73.     //{{AFX_MSG_MAP(COptionsGeneralPage)
  74.         // HINWEIS: Der Klassen-Assistent fⁿgt hier Zuordnungsmakros fⁿr Nachrichten ein
  75.     //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // Behandlungsroutinen fⁿr Nachrichten COptionsGeneralPage 
  80.  
  81. BOOL COptionsGeneralPage::IsDataValid()
  82. {
  83.     if (!UpdateData(TRUE))
  84.         return FALSE;
  85.  
  86.     std::set<int> portSet;
  87.     bool valid = true;
  88.     
  89.     CString ports = m_Port;
  90.     ports.TrimLeft(_T(" ,"));
  91.  
  92.     int pos = ports.FindOneOf(_T(" ,"));
  93.     while (pos != -1 && valid)
  94.     {
  95.         int port = _ttoi(ports.Left(pos));
  96.         if (port < 1 || port > 65535)
  97.         {
  98.             valid = false;
  99.             break;
  100.         }
  101.         else
  102.             portSet.insert(port);
  103.         ports = ports.Mid(pos + 1);
  104.         ports.TrimLeft(_T(" ,"));
  105.         pos = ports.FindOneOf(_T(" ,"));
  106.     }
  107.     if (valid && ports != _T(""))
  108.     {
  109.         int port = _ttoi(ports);
  110.         if (port < 1 || port > 65535)
  111.             valid = false;
  112.         else
  113.             portSet.insert(port);
  114.     }
  115.  
  116.     if (!valid)
  117.     {
  118.         m_pOptionsDlg->ShowPage(this);
  119.         GetDlgItem(IDC_PORT)->SetFocus();
  120.         AfxMessageBox(_T("Invalid port found, please only enter ports in the range from 1 to 65535."));
  121.         return FALSE;
  122.     }
  123.     int threadnum = _ttoi(m_Threadnum);
  124.     if (threadnum < 1 || threadnum > 50)
  125.     {
  126.         m_pOptionsDlg->ShowPage(this);
  127.         GetDlgItem(IDC_THREADNUM)->SetFocus();
  128.         AfxMessageBox(_T("Please enter a value between 1 and 50 for the number of Threads!"));
  129.         return FALSE;
  130.     }
  131.  
  132.     m_Port = _T("");
  133.     for (std::set<int>::const_iterator iter = portSet.begin(); iter != portSet.end(); iter++)
  134.     {
  135.         CString tmp;
  136.         tmp.Format(_T("%d "), *iter);
  137.         m_Port += tmp;
  138.     }
  139.     m_Port.TrimRight(' ');
  140.     UpdateData(false);
  141.  
  142.     return TRUE;
  143. }
  144.  
  145. void COptionsGeneralPage::LoadData()
  146. {
  147.     m_Port = m_pOptionsDlg->GetOption(OPTION_SERVERPORT);
  148.     m_Threadnum.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_THREADNUM)));
  149.     m_MaxUsers.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_MAXUSERS)));
  150.     m_Timeout.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_TIMEOUT)));
  151.     m_NoTransferTimeout.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_NOTRANSFERTIMEOUT)));
  152.     m_LoginTimeout.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_LOGINTIMEOUT)));
  153. }
  154.  
  155. void COptionsGeneralPage::SaveData()
  156. {
  157.     m_pOptionsDlg->SetOption(OPTION_SERVERPORT, m_Port);
  158.     m_pOptionsDlg->SetOption(OPTION_THREADNUM, _ttoi(m_Threadnum));
  159.     m_pOptionsDlg->SetOption(OPTION_MAXUSERS, _ttoi(m_MaxUsers));
  160.     m_pOptionsDlg->SetOption(OPTION_TIMEOUT, _ttoi(m_Timeout));
  161.     m_pOptionsDlg->SetOption(OPTION_NOTRANSFERTIMEOUT, _ttoi(m_NoTransferTimeout));
  162.     m_pOptionsDlg->SetOption(OPTION_LOGINTIMEOUT, _ttoi(m_LoginTimeout));
  163. }